
function fun(selector){
		var result = document.querySelectorAll(selector);
		if(result.length === 1){
			return result[0]
		}
		return result;
	}

// 轮播图
let next=fun(".fav .button-next");
let prev=fun(".fav .button-prev");
let Items=fun(".fav ul")

next.onclick=function(){
	Items.style.marginLeft="-914px";
	Items.style.transition= "all 1s";
}
prev.onclick=function(){
	Items.style.marginLeft="0"
	Items.style.transition= "all 1s";
}


let Particulars=fun("#particulars");
let Evaluate=fun("#evaluate");
let Xdetail=fun("#tab_con .x-detail");
let ComTop=fun("#tab_con .x-comment");

// console.log(ComTop)
// console.log(Particulars);
// console.log(Evaluate)
Particulars.onclick=function(){
	Particulars.className="active";
	Evaluate.className="";
	Xdetail.style.display="none";
	Xdetail.style.display="block";
	ComTop.style.display="none";
}
Evaluate.onclick=function(){
	Evaluate.className="active";
	Particulars.className="";
	Xdetail.style.display="none";
	ComTop.style.display="block"
}

let Filter=fun(".filter li");
let Span=fun(".filter li span")[1];
let P1=fun("#P1");
let P2=fun("#P2");
let a=Span.innerHTML;
let c= Number (a.substring(7,8));



// console.log(P1)
// console.log(P2)
// console.log(Filter)
Filter[0].onclick=function(){
	Filter[0].id="red";
	Filter[1].id="";
	P1.style.display="block";
	P2.style.display="none";
}
Filter[1].onclick=function(){
	Filter[1].id="red";
	Filter[0].id="";
	P1.style.display="none";
	P2.style.display="block";
}

let Fb=fun(".ping #fb");
let Template=fun("#template");
let Textarea=fun("textarea");
let  Ptext=fun("#template p");
// console.log(Ptext)
let Time=fun("#template #Time");

  let date = new Date();
	
	function toTwo(v){
		return v<10?"0"+v:v;
	}	
	function dateToString(d){
		
		let _y = d.getFullYear();
		let _m = toTwo(d.getMonth()+1);
		let _d = toTwo(d.getDate());
		let _h = d.getHours();
		let _mm = d.getMinutes();
		
		let str = _y+"-"+_m+"-"+_d+" "+_h+":"+_mm;
		
		return str;
	}
	
	// console.log(dateToString(date));
	
let T=dateToString(date);
	
Fb.onclick=function(){
// console.log(Textarea.value)
	let newli=Template.cloneNode(true);
	newli.id="";
	newli.querySelector("p").innerHTML =Textarea.value;
	Textarea.value = "";
	// console.log(Ptext)
	P1.appendChild(newli);
	c=c+1;
	Span.innerHTML=c;
	Time.innerHTML=T;	
}

let Plus = fun("#plus");
let Reduce = fun("#reduce");
let Num = fun("#quantity");


Plus.onclick = function(){
Num.value1 = parseInt(Num.value);
Num.value = Num.value1 + 1;
}

Reduce.onclick = function(){
	if(Num.value == 1){
		Num.value = 1
	}else{
		Num.value1 = parseInt(Num.value);
		Num.value = Num.value1 - 1;
	}
}

// 加入购物车
$(function(){$("#ButtonAddCart").click (function(){
		alert("加入购物车成功");
		$("#total").html($("#quantity").val());
		$("#total2").html($("#quantity").val());
	})
	
})
	
// Add.onclick = function(){
// 	alert("加入购物车成功");
// 	console.log(Num.value);
// 	debugger
// 	console.log(Total1);
// 	Total1.value = Num.value;
// 	Total2.value = Num.value;
// }